package cn.bluemobi.dylan.step.ui.my.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.scwang.smartrefresh.layout.api.RefreshLayout;

import java.util.List;

import butterknife.BindView;
import cn.bluemobi.dylan.step.R;
import cn.bluemobi.dylan.step.base.BaseMvpActivity;
import cn.bluemobi.dylan.step.moder.bean.Goods;
import cn.bluemobi.dylan.step.moder.bean.MemberAccount;
import cn.bluemobi.dylan.step.moder.bean.User;
import cn.bluemobi.dylan.step.presenter.contract.my.InfoEditContract;
import cn.bluemobi.dylan.step.presenter.contract.my.IntegralContract;
import cn.bluemobi.dylan.step.presenter.my.activity.InfoEditPresenter;
import cn.bluemobi.dylan.step.presenter.my.activity.IntegralPresenter;
import cn.bluemobi.dylan.step.ui.my.adapter.GoodsAdapter;
import cn.bluemobi.dylan.step.view.CommProgressDailog;

/**
 * 积分兑换
 */
public class InfoEditActivity extends BaseMvpActivity<InfoEditPresenter> implements InfoEditContract.View {

    @BindView(R.id.tool_bar)
    Toolbar mToolbar;
    @BindView(R.id.toolbar_back)
    ImageView toolbar_back;
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_right)
    TextView tv_right;
    @BindView(R.id.et_nickName)
    EditText et_nickName;

    private User user;
    CommProgressDailog progressDialog;

    @Override
    protected int getLayout() {
        return R.layout.my_info_edit;
    }

    @Override
    protected void initView() {
        super.initView();
        initToolbar();
        user = (User) getIntent().getSerializableExtra("User");
        if(user!=null){
            et_nickName.setText(user.memberNickName);
        }
        progressDialog = new CommProgressDailog();

    }

    private void initToolbar() {
        setSupportActionBar(mToolbar);
        tv_title.setText("编辑");
        tv_right.setVisibility(View.VISIBLE);
        tv_right.setText("完成");
        tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!TextUtils.isEmpty(et_nickName.getText().toString().trim())){
                    mPresenter.updateMember(user.memberId,et_nickName.getText().toString().trim());
                }else {
                    Toast.makeText(InfoEditActivity.this,"请输入昵称",Toast.LENGTH_LONG).show();
                }

            }
        });
        toolbar_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }



    @Override
    public void showUserInfo(User user) {
        if (user != null) {
            this.user = user;
            Intent intent = new Intent();
            intent.putExtra("User",user);
            setResult(1,intent);
            finish();
        }
    }

    @Override
    public void showMemberAccount(MemberAccount memberAccount) {  //积分

    }

    @Override
    public void httpGoods(List<Goods> result) {

    }

    @Override
    public void buyGoodsSuccess(Goods result) { //商品兑换成功

    }




    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }


    @Override
    public void showError(String msg) {

    }

    @Override
    public void showDialog() {
        if(progressDialog!=null){
            progressDialog.showProgressDailog(this);
        }
    }

    @Override
    public void closeDialog() {
        if(progressDialog!=null){
            progressDialog.cancelProgressDailog();
        }
    }

}
